var express = require('express'); 
var app = express(); 
var net = require('net');
var util = require('util');
var gatewayPort = 5327;
var gatewayHost = '10.5.6.118';
var loginRequest = {"CommuniqueType":"CreateRequest","Header":{"Url":"\/login"},"Body":{"UserCredentials":{"ApplicationType":"QAdmin","ContextName":"APPLICATION","ContextType":"Application","LoginId":"admin","Password":"25F43B1486AD95A1398E3EEB3D83BC4010015FCC9BEDB35B432E00298D5021F7"}}};
var projectInfoRequest = '{"CommuniqueType":"ReadRequest","Header":{"Url":"/project"}}\r\n';

// Configuration 
app.configure( function() { 
}); 

// Routes 
app.get('/', function(req, res) { 
    res.send( util.format("%j", loginRequest)); 
}); 

app.get('/area', function(req, res) { 
    res.send('area'); 
}); 


var client = net.connect({port:gatewayPort,host:gatewayHost}, function(){
					console.log ('client connected to gateway');
					console.log ('sending login');
					client.write(projectInfoRequest);
					console.log ('sent');
			});
	
client.setEncoding('utf8');
//client.setKeepAlive(true);	
//client.setNoDelay(true);	
client.on('data', function(data){
	console.log ('data received');
	console.log(data);
});

client.on('error', function(data){
	console.log ('error received');
	console.log(data);
});

app.listen(3333); 